package api

import (
	"demo/src/app"
	"demo/src/controller"
	"demo/src/service/test"
	"log"
	"net/http"
)

func init() {
	log.Println("test controller init")
	app.Application.Controller(new(TestController))
}

type TestController struct {
	TestService test.ITestService `bean:"TestServiceImpl"`
	app.CommonComponent
}

func (t *TestController) ToHandlers() []controller.Handler {
	handlers := make([]controller.Handler, 0)
	handlers = append(handlers, t.test())
	return handlers
}

func (t *TestController) test() controller.Handler {
	return controller.GetHandler("/test", func(ctx map[string]any, req *http.Request, w http.ResponseWriter) {
		w.Write([]byte(t.TestService.DoTest()))
	})
}
